Fast, efficient, and easy-to-use array extensions for TypeScript.
Packages
Installation
npm install @ariesclark/extensions
npm install @ariesclark/array
Documentation
group
(function)
Groups the items in the array by the given function.
group([1, 2, 3, 4, 5], item => (item % 2 === 0 ? 'even' : 'odd'));
randomIndex
(function)
Get a random index from an array, with an optional random number generator.
Parameters:
- array (
{ length: 0; }
) - random (
RandomFunction
)
returns: null
const value = ['lorem', 'ipsum', 'dolor', 'sit', 'amet'];
randomIndex(value);
randomIndex(value);
randomIndex(value);
randomIndex
(function)
Parameters:
- array (
{ length: number; }
) - random (
RandomFunction
)
returns: null
randomIndex
(function)
Parameters:
- array (
{ length: number; }
) - random (
RandomFunction
)
returns: null
randomItem
(function)
Get a random item from an array, with an optional random number generator.
Parameters:
- array (
{ length: 0; }
) - random (
RandomFunction
)
returns: null
const value = ['lorem', 'ipsum', 'dolor', 'sit', 'amet'];
randomItem(value);
randomItem(value);
randomItem(value);
randomItem
(function)
Parameters:
- array (
{ [index: number]: T; length: number; }
) - random (
RandomFunction
)
returns: null
randomItem
(function)
Parameters:
- array (
{ [index: number]: T; length: number; }
) - random (
RandomFunction
)
returns: null
unique
(function)
Returns a new array with unique values based on the by
function.
Parameters:
- array (
T[]
) - by (
(value: T) => unknown
)
returns: T[]
{ from, fromAsync, isArray, of }
(variable)